﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thinger.VisitionDAL
{
  public  class DataProcessing
    {

        /// <summary>
        /// 解析两个坐标轴
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public   (string x ,string y ) CoordinateProcessing(string data)
        {
            string[] values = data.Split(new char[] { ',' }, StringSplitOptions.None);
            return (values[0],values[1]);

        }

        /// <summary>
        /// 两个坐标值组合
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public  string  CoordinateMontage(double x,double y)
        {
            string str1 = x.ToString();
            string str2 = y.ToString();
            string str = str1 + "," + str2;
            return str;
        }


        /// <summary>
        /// 将获得轴的位置信息提取数字信息
        /// </summary>
        /// <param name="axis"></param>
        /// <returns></returns>
        public double AxisPosPrecessToDouPos(string axis)
        {
            string str1 = axis.Replace("m","").Trim();
            string str2 = str1.Replace("°", "").Trim();
            string str3 = str2.Substring(str2.IndexOf("：") +1);
            return Convert.ToDouble(str3);

        }

        /// <summary>
        /// 丝杆位置值转到轴的位置脉冲数 
        /// </summary>
        /// <param name="mm"></param>
        /// <param name="length"></param>
        /// <param name="pulRad"></param>
        /// <returns></returns>
        public double AxismmToPul(double mm , double length, double pulCycle)
        {

            double pul_Length = pulCycle / length;
            return mm * pul_Length;
        }

        /// <summary>
        /// 轴实时位置转化位mm
        /// </summary>
        /// <param name="pul"></param>
        /// <param name="length"></param>
        /// <param name="pulCycle"></param>
        /// <returns></returns>
        public double AxisPulTomm(double pul, double length, double pulCycle)
        {

            double length_Pul = length/pulCycle;
            return pul * length_Pul;
        }


        /// <summary>
        /// 角度位置值转到轴的位置脉冲数 
        /// </summary>
        /// <param name="angle"></param>
        /// <param name="cycle"></param>
        /// <param name="pulCycle"></param>
        /// <returns></returns>
        public double AxisAngleToPul(double angle, double pulCycle, double cycle = 360.0)
        {
            double pul_Cycle = pulCycle / cycle;
            return angle * pul_Cycle;
        }

        /// <summary>
        /// 旋转位置脉冲转化位角度值
        /// </summary>
        /// <param name="pul"></param>
        /// <param name="pulCycle"></param>
        /// <param name="cycle"></param>
        /// <returns></returns>
        public double AxisPulToAngle(double pul, double pulCycle, double cycle = 360.0)
        {
            double cycle_Pul = cycle / pulCycle;
            return pul * cycle_Pul;
        }
    }
}
